﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/SiteMaster.master"
    CodeBehind="ViewTasks.aspx.cs" Inherits="CivilleWebRole.ViewTasks" %>

<%@ Register Assembly="CivilleWebRole" Namespace="CivilleWebRole" TagPrefix="cc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="BodyContent">
    <table style="width: 100%;">
        <tr>
            <td align="left" class="style1" colspan="2">
                <asp:Label ID="ViewTasksLbl" runat="server" Text="Here are your tasks:" Font-Size="Large"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
                <asp:GridView ID="TasksGridView" runat="server" AutoGenerateColumns="False" AllowPaging="True"
                    AllowSorting="True" DataKeyNames="ID" EmptyDataText="There are no data records to display."
                    DataSourceID="CivilleAzureSqlDataSource" OnRowUpdating="TasksGridView_RowUpdating">
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                            SortExpression="ID" />
                        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:BoundField DataField="Latitude" HeaderText="Latitude" SortExpression="Latitude" />
                        <asp:BoundField DataField="Longitude" HeaderText="Longitude" SortExpression="Longitude" />
                        <asp:BoundField DataField="Points" HeaderText="Points" SortExpression="Points" />
                        <asp:TemplateField HeaderText="Logo">
                            <ItemTemplate>
                                <asp:Image ImageUrl='<%# Eval("Logo") %>' runat="server" ID="logo" Height="100" Width="100" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:FileUpload ID="LogoFileUpload" runat="server" />
                            </EditItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="CivilleAzureSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CivilleConnectionString %>"
                    SelectCommand="SELECT [Task].[ID], [Task].[Title], [Task].[Description], [Task].[Latitude], [Task].[Longitude], [Task].[Points], [Task].[Logo], [Stakeholder].[Name] FROM [Task], [Stakeholder] WHERE [Stakeholder].[Name] = @Name AND [Task].[StakeholderID] = [Stakeholder].[ID]"
                    DeleteCommand="DELETE FROM [Task] WHERE [ID] = @id" InsertCommand="INSERT INTO [Task] ([Title], [Description], [Latitude], [Longitude], [Points], [StakeholderID]) VALUES (@Title, @Description, @Latitude, @Longitude, @Points, @StakeholderID)"
                    UpdateCommand="UPDATE [Task] SET [Title] = @Title, [Description] = @Description, [Latitude] = @Latitude, [Longitude] = @Longitude, [Points] = @Points, [Logo] = @Logo WHERE [ID] = @id">
                    <SelectParameters>
                        <cc1:UserParameter Name="Name" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="ID" Type="Int32" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="Title" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Latitude" Type="Double" />
                        <asp:Parameter Name="Longitude" Type="Double" />
                        <asp:Parameter Name="Points" Type="Int32" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Title" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Latitude" Type="Double" />
                        <asp:Parameter Name="Longitude" Type="Double" />
                        <asp:Parameter Name="Points" Type="Int32" />
                        <asp:Parameter Name="ID" Type="Int32" />
                        <asp:Parameter Name="Logo" DefaultValue="Logo/Tasks/default.gif" />
                    </UpdateParameters>
                </asp:SqlDataSource>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
                <asp:HyperLink ID="SuggestedTasksHL" runat="server">View Suggested Tasks</asp:HyperLink>
            </td>
            <td>
                &nbsp;
                <asp:HyperLink ID="CreateTaskHL" runat="server">Add New Tasks</asp:HyperLink>
            </td>
        </tr>
    </table>
</asp:Content>
